dcmotor31 2.2.1
Loading...
Searching...
No Matches
dcmotor31


DC Motor 31 Click

DC Motor 31 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Jul 2025.
  • Type : I2C type

Software Support

Example Description

This example demonstrates the operation of the DC Motor 31 Click board by alternating the motor direction between forward and reverse with braking in between.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.DCMotor31

Example Key Functions

  • dcmotor31_cfg_setup This function initializes Click configuration structure to initial values.
    void dcmotor31_cfg_setup(dcmotor31_cfg_t *cfg)
    DC Motor 31 configuration object setup function.
    DC Motor 31 Click configuration object.
    Definition dcmotor31.h:218
  • dcmotor31_init This function initializes all necessary pins and peripherals used for this Click board.
    err_t dcmotor31_init(dcmotor31_t *ctx, dcmotor31_cfg_t *cfg)
    DC Motor 31 initialization function.
    DC Motor 31 Click context object.
    Definition dcmotor31.h:195
  • dcmotor31_default_cfg This function executes a default configuration of DC Motor 31 Click board.
    err_t dcmotor31_default_cfg(dcmotor31_t *ctx)
    DC Motor 31 default configuration function.
  • dcmotor31_set_mode This function sets the motor control mode to forward, reverse, or brake.
    void dcmotor31_set_mode ( dcmotor31_t *ctx, uint8_t mode );
    void dcmotor31_set_mode(dcmotor31_t *ctx, uint8_t mode)
    DC Motor 31 set operation mode function.
  • dcmotor31_set_torque This function sets the output torque by writing to the OUTPUT register.
    err_t dcmotor31_set_torque ( dcmotor31_t *ctx, uint8_t torque );
    err_t dcmotor31_set_torque(dcmotor31_t *ctx, uint8_t torque)
    DC Motor 31 set torque function.

Application Init

Initializes the logger and the Click board, then applies the default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
dcmotor31_cfg_t dcmotor31_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
dcmotor31_cfg_setup( &dcmotor31_cfg );
if ( I2C_MASTER_ERROR == dcmotor31_init( &dcmotor31, &dcmotor31_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( DCMOTOR31_ERROR == dcmotor31_default_cfg ( &dcmotor31 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
@ DCMOTOR31_ERROR
Definition dcmotor31.h:240
#define DCMOTOR31_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition dcmotor31.h:178
#define MIKROBUS_POSITION_DCMOTOR31
Definition main.c:27
void application_init(void)
Definition main.c:33

Application Task

Changes the motor direction from forward to reverse with a brake period in between, and logs the current motor state on the UART terminal.

void application_task ( void )
{
log_printf( &logger, " Motor state : FORWARD\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, " Motor state : BRAKE\r\n\n" );
Delay_ms ( 1000 );
log_printf( &logger, " Motor state : REVERSE\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, " Motor state : BRAKE\r\n\n" );
Delay_ms ( 1000 );
}
#define DCMOTOR31_MODE_FORWARD
Definition dcmotor31.h:149
#define DCMOTOR31_MODE_BRAKE
DC Motor 31 operating mode setting.
Definition dcmotor31.h:148
#define DCMOTOR31_MODE_REVERSE
Definition dcmotor31.h:150
void application_task(void)
Definition main.c:69

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.